package protocol

import java.io.IOException

import org.apache.hadoop.ipc.{ProtocolInfo, ProtocolSignature, RPC, VersionedProtocol}

/**
 * 继承 VersionedProtocol 接口，并使用注解方式指定 Protocol 名称及版本号
 */
@ProtocolInfo(protocolName = "protocol.Info", protocolVersion = 1)
trait Info extends VersionedProtocol {
  // 根据学号返回姓名
  def findName(xh: String): String

  override def getProtocolVersion(protocol: String, clientVersion: Long): Long = {
    RPC.getProtocolVersion(classOf[Info])
  }

  override def getProtocolSignature(protocol: String, clientVersion: Long, clientMethodsHash: Int): ProtocolSignature = {
    if (!RPC.getProtocolName(classOf[Info]).equals(protocol)) {
      throw new IOException(s"Serverside implements ${RPC.getProtocolName(classOf[Info])} The following requested protocol is unknown: ${protocol}")
    }
    ProtocolSignature.getProtocolSignature(clientMethodsHash, RPC.getProtocolVersion(classOf[Info]), classOf[Info])
  }
}
